<template>
  <div class="app-container">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" :label-width="labelWidth">
        <el-form-item label="订单类型：" prop="orderType">
          <el-select v-model="queryParams.orderType" placeholder="请选择" filterable clearable
            :style="{width: inputWidth}">
            <el-option v-for="dict in couponTypeLs" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单编号：" prop="orderNo">
          <el-input v-model="queryParams.orderNo" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="活动名称：" prop="activityName">
          <el-input v-model="queryParams.activityName" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="券码：" prop="couponNo">
          <el-input v-model="queryParams.couponNo" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="产品名称：" prop="couponName">
          <el-input v-model="queryParams.couponName" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="会员姓名：" prop="customerName">
          <el-input v-model="queryParams.customerName" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="手机号码：" prop="phone">
          <el-input v-model="queryParams.phone" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="券状态：" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择" filterable clearable :style="{width: inputWidth}">
            <el-option v-for="(item,index) in couponStatusLs" :key="index" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="备注：" prop="remark">
          <el-input v-model="queryParams.remark" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="核销店铺：" prop="shopIdList" :key="19">
          <el-select v-model="queryParams.shopIdList" multiple placeholder="请选择" filterable clearable
            :style="{width: inputWidth}">
            <el-option v-for="(item,index) in shopList" :key="index" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="核销时间：" prop="">
          <el-date-picker v-model="dateTwo" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>

        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <el-button type="primary" @click="verificationCode" :disabled="productIds.length>0?false:true">核销券码</el-button>
        <export-excel-button title="打卡券码明细" action="/shenye/customer/coupon/coupon/detail/export" :type="'2'"
          :params="ExportParams" />
      </div>
      <el-table v-loading="loading" :data="tabList" stripe border row-key="id"
        @selection-change="handleSelectionChange" ref="multipleTable">
        <el-table-column type="selection" :reserve-selection="true" width="55" fixed="left" :selectable="selected">
        </el-table-column>
        <el-table-column label="序号" align="center" type="index" width="64px" fixed="left" />
        <el-table-column label="订单编号" align="center" prop="orderNo" />
        <el-table-column label="订单类型" align="center" prop="orderType" :show-overflow-tooltip="true" width="120px">
          <template slot-scope="scope">
            <div v-if="scope.row.orderType == 1">数字宝箱</div>
            <div v-if="scope.row.orderType == 2">第三方充值</div>
          </template>
        </el-table-column>
        <el-table-column label="活动名称" align="center" prop="activityName" />
        <el-table-column label="姓名" align="center" prop="customerName" />
        <el-table-column label="手机号" align="center" prop="phone" />
        <el-table-column label="产品名称" align="center" prop="couponName" />
        <el-table-column label="券码" align="center" prop="couponNo" width="120" />
        <el-table-column label="券有效期" align="center" prop="validityTime" width="100">
          <template slot-scope="scope">
            <div>{{scope.row.validityTime}}</div>
          </template>
        </el-table-column>
        <el-table-column label="券状态" align="center" prop="status" :show-overflow-tooltip="true" width="120px">
            <template slot-scope="scope">
            <dict-tag :options="couponStatusLs" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="核销店铺" align="center" prop="shopName" />
        <el-table-column label="核销时间" align="center" prop="verificationTime" width="155" />
        <el-table-column label="备注" align="center" prop="remark" />
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <Dialog ref="dialog" @refresh="_handleSuccess"></Dialog>
  </div>
</template>

<script>
  import {
    shenyeCouponList,
    shopList,
    couponCount,
    couponShopList
  } from "@/api/consumeMiningManagement/clockingCouponCode";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import Dialog from "@/views/consumeMiningManagement/clockingCouponCode/components/dialog";
  export default {
    // dicts: ['equity_card_issue_type', 'equity_card_sell_status'],
    name: "",
    components: {
      ExportExcelButton,
      Dialog
    },
    data() {
      return {
        labelWidth: '100px',
        inputWidth: '200px',
        //日期
        date: [],
        dateTwo: [],
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        productIds: [],
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        tabList: [],
        // 查询参数
        queryParams: {
          activityName: '', //活动名称
          couponName: '', //产品名称
          couponNo: '', //	券码
          customerName: '',//姓名
          orderNo: '',//订单编号
          orderType: '',//订单类型 1 数字宝箱 2第三方充值
          pageNum: 1,
          pageSize: 10,
          phone: '',//手机号码
          remark: '',//备注
          shopIdList: [], //店铺id数组
          status: '', //状态 shenye_customer_coupon_status 1 待使用 2 已核销 3 已退款 4 已过期
          verificationEndTime: '', //核销结束时间
          verificationStartTime: '', //核销开始时间
        },
        shopList: [], //店铺下拉
        couponTypeLs: [
          {
            id: "",
            value: "全部",
          }, 
          {
            id: '1',
            value: '数字宝箱',
          },
          {
            id: '2',
            value: '第三方充值',
          },
        ], //券类型下啦
        couponStatusLs: [], //状态下拉
        info: {},
        dialogVisible: false, //弹窗状态
        dialogId: '', //弹窗id
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      this.getDict()
      this.getShopList()
      let id = this.$route.query.id
      if (id != undefined) {
        this.queryParams.shopIdList = [id]
      }
      // this.queryParams.shopIdList = this.queryParams.shopIdList[0] = id
      console.log(this.queryParams.shopIdList)
      
    },
    mounted(){
      this.getList();
    },
    methods: {
      //获取券状态
      getDict() {
        var dictType = "shenye_customer_coupon_status";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.couponStatusLs = arr.concat(res.result[0].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //查询核销店铺下拉框
      getShopList() {
        shopList().then(response => {
          this.shopList = response.result
        });
      },
      selected(row, index) {
        console.log('row',row)
        if (row.couponNo != '' && row.status == 1) {
          return true //不可勾选
        } else {
          return false; //可勾选
        }
      },
      /** 查询列表 */
      getList() {
        this.$refs.multipleTable.clearSelection();
        this.loading = true;
        shenyeCouponList(this.queryParams).then(response => {
          this.tabList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
          console.log('this.loading',this.loading)

        });
      },
     
      // 表单重置
      resetQuery() {
        this.date = []
        this.dateTwo = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          buyEndTime: '', //购买结束时间
          buyStartTime: '', //购买开始时间
          couponType: '', //券类型 shenye_punch_activity_coupon_type
          query: '', //券码/活动名称/券名称/会员姓名/手机号
          shopIdList: [], //店铺id数组
          status: '', //状态 shenye_customer_coupon_status 1 待使用 2 已核销 3 已退款 4 已过期
          verificationEndTime: '', //核销结束时间
          verificationStartTime: '', //核销开始时间
        }
        // this.resetForm("form");
        this.getList();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.buyStartTime = this.date[0];
        this.queryParams.buyEndTime = this.date[1];
        this.queryParams.verificationStartTime = this.dateTwo[0];
        this.queryParams.verificationEndTime = this.dateTwo[1];
        this.queryParams.pageNum = 1;
        this.getList();
      },
      _handleSuccess(e) {
        //成功回调
        // this.resetQuery()
        this.getList()
        this.productIds = []
        
      },
      /** 多选框选中数据 */
      handleSelectionChange(selection) {
        this.productIds = selection.map(item => item.id)
        console.log(this.productIds)
      },
     
      // verificationCode(){ //核销券码
      //   console.log(this.productIds)
      //   this.$confirm(`已选择${this.productIds.length}条记录是否确认核销`, '批量核销券码', {
      //     confirmButtonText: '确认核销',
      //     cancelButtonText: '取消',
      //     type: 'warning'
      //   }).then(() => {
      //     this.$message({
      //       type: 'success',
      //       message: '操作成功!'
      //     });
      //   }).catch(() => {});
      // },
      /** 按钮操作 */
      verificationCode() {
        this.$refs.dialog.open(this.productIds);
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    padding-bottom: 20px;
    display: flex;
    justify-content: space-between;
  }

  .num_detail {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid #dfe6ec;
    border-radius: 10px;
    padding: 20px 10px 0;
    margin-bottom: 20px;
  }

  .num_detail_box {
    color: #333;
    font-size: 15px;
    margin-right: 30px;
    margin-bottom: 20px;
  }

</style>
